/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.metadata;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Martin Řehánek, rehan at mzk.cz
 */
public enum MetadataFormat {

    marc21 {

        @Override
        public URL getSchemaUrl() {
            return url("http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd");
        }

        @Override
        public String getNamespaceUri() {
            return "http://www.loc.gov/MARC21/slim";
        }

        @Override
        public String getDirName() {
            return "marc21";
        }
    },
    ese {

        @Override
        public URL getSchemaUrl() {
            return url("http://www.europeana.eu/schemas/ese/ESE-V3.2.xsd");
        }

        @Override
        public String getNamespaceUri() {
            return "http://www.openarchives.org/OAI/2.0/oai_dc/";
        }

        @Override
        public String getDirName() {
            return "ese";
        }
    }, oai_dc {

        @Override
        public URL getSchemaUrl() {
            return url("http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
        }

        @Override
        public String getNamespaceUri() {
            return "http://www.openarchives.org/OAI/2.0/oai_dc/";
        }

        @Override
        public String getDirName() {
            return "oai_dc";
        }
    }, tei_p5 {

        @Override
        public URL getSchemaUrl() {
            return url("http://tei.oucs.ox.ac.uk/Projects/ENRICH/ODD/RomaResults/enrich.dtd");
        }

        @Override
        public String getNamespaceUri() {
            return "http://www.tei-c.org/ns/1.0";
        }

        @Override
        public String getDirName() {
            return "tei_p5";
        }
    };

    public static MetadataFormat parseString(String string) {
        for (MetadataFormat format : MetadataFormat.values()) {
            if (format.toString().equals(string)) {
                return format;
            }
        }
        throw new IllegalArgumentException("no such metadata format '" + string + "'");
    }

    public abstract URL getSchemaUrl();

    public abstract String getNamespaceUri();

    public abstract String getDirName();

    protected URL url(String string) {
        try {
            return new URL(string);
        } catch (MalformedURLException ex) {
            //should never happen
            Logger.getLogger(MetadataFormat.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
